﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T11Func
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("求两数之和:{0}", MyMath.Sum(1, 2));
            Console.WriteLine("求多个数之和:{0}", MyMath.Sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
            Console.WriteLine("求多个数之和:{0}", MyMath.Sum());

            int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int? maxIndex = null;
            int? max = MyMath.Max(number, ref maxIndex);
            Console.WriteLine("最大值:{0},索引为:{1}", max, maxIndex
            int ? max2 = MyMath.Max(number, ref maxIndex);

        }
    }

    /// <summary>
    /// 自定义数学函数库
    /// </summary>
    class MyMath
    {
        /// <summary>
        /// 求两个数的和
        /// </summary>
        /// <param  name="a">操作数一</param>
        /// <param  name="b">操作数二</param>
        /// <returns>两数之和</returns>
        public static int Sum(int a,int b)
        {
            //int result = 0;
            //result = a + b;
            //return result;
            return a + b;
        }
        /// <summary>
        /// 求多个数的和
        /// </summary>
        /// <param name="values">操作数集合（param 可变长参数列表0或n个）</param>
        /// <returns>多个数之和(可空值）</returns>
        public static int? Sum(params int [] values)
        {
            int? result = null ;
            if (values.Length > 0)
            {
                result = 0;


                //局部变量可使用var定义变量，类型推断
                foreach (var value in values)
                {
                    result += value;
                }

            }
            return result;
        }

        public static int? Min (int[] values,out int ?minIndex)
        {
            minIndex = null;
            return null;
        }
        else 
        {
        var
        
        }
    }
}
